package com.sangfor.ssl.l3vpn.service;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Pair;
import com.sangfor.bugreport.logger.Log;
import com.sangfor.ssl.LineSelectionModel;
import com.sangfor.ssl.SangforAuthManager;
import com.sangfor.ssl.l3vpn.service.EasyappSvpnService;
import com.sangfor.ssl.l3vpn.service.networkInfo.NetworkInterceptInfoModel;
import com.sangfor.ssl.l3vpn.service.networkInfo.PacketInfo;
import com.sangfor.ssl.service.setting.ResourceManager;
import com.sangfor.ssl.service.setting.SettingManager;
import com.sangfor.ssl.service.setting.SystemConfiguration;
import com.sangfor.ssl.service.utils.AndroidDnsServer;
import com.sangfor.ssl.service.utils.RomUtils;
import java.lang.ref.WeakReference;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

/* loaded from: classes2.dex */
public class VpnServiceManager implements EasyappSvpnService.ICallback {
    public static final String LAUNCH_TYPE_KEY = "vpnservice.launch.nettype";
    public static final String LOGIN_STATE_KEY = "vpnservice.launch.loginstate";
    private static String TAG = "VpnServiceManager";
    private Context mAppContext;
    private Object mCaptureLock;
    private long mCapturePtr;
    private VpnConfigUtil mConfigUtil;
    private Handler mHandler;
    private AtomicBoolean mIsInit;
    private LaunchMode mLastMode;
    private ArrayList<WeakReference<IVpnStatusChangedListener>> mList;
    private LaunchMode mMode;
    private LoginState mState;
    private EasyappSvpnService.IManager mTunManager;
    private VpnStatus mVpnStatus;

    private boolean isEMMLineEnable() {
        return false;
    }

    private native boolean nativeIsCaptureComplete(long j);

    private native int nativeRestartTun();

    private native int nativeSetRunTimeInfo(String str, String str2);

    private native long nativeStartCapturePacket(String str, int i, long j, long j2, boolean z);

    private native boolean nativeStartProxy(int i, int i2, String str, String str2);

    private native int nativeStopCapturePacket(long j);

    private native void nativeStopProxy();

    private native void nativeUpdateAclEnable(int i);

    private native void nativeUpdateAclist(List<AllowType> list);

    private native void nativeUpdateRclist(List<ResType> list);

    private native void nativeUpdateRuntimeInfo(String str);

    private native void nativeUpdateState(int i);

    public native void nativeExit();

    public native void nativeNetworkChanged(boolean z);

    static {
        System.loadLibrary("svpnservice");
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes2.dex */
    public static final class VpnServiceManagerHolder {
        public static final VpnServiceManager INSTANCE = new VpnServiceManager();

        private VpnServiceManagerHolder() {
        }
    }

    public static final VpnServiceManager getInstance() {
        return VpnServiceManagerHolder.INSTANCE;
    }

    public void init(Context context) {
        this.mAppContext = context.getApplicationContext();
        this.mIsInit.set(true);
    }

    public Boolean isInit() {
        return Boolean.valueOf(this.mIsInit.get());
    }

    public synchronized void setShutDownStatus(boolean z) {
        SettingManager.getInstance().setGlobalValue(SettingManager.GLOBAL_SHUTDOWN_STATE, Boolean.valueOf(z));
        updateLoginState(LoginState.LOGIN_STATE_OFFLINE);
    }

    public synchronized void networkChanged(boolean z) {
        nativeNetworkChanged(z);
    }

    public void setRunTimeInfo(String str, String str2) {
        if (str == null || str2 == null) {
            return;
        }
        nativeSetRunTimeInfo(str, str2);
    }

    public void updateLoginState(LoginState loginState) {
        String str = TAG;
        Log.info(str, "current mode is " + this.mMode.name() + "; current state is " + this.mState.name() + "; new state is " + loginState.name());
        if (loginState == LoginState.LOGIN_STATE_LAST) {
            Log.info(TAG, "update launch mode failed, invalid launch mode.");
            return;
        }
        if (LoginState.LOGIN_STATE_ONLINE == loginState) {
            nativeUpdateState(LoginState.LOGIN_STATE_OFFLINE.intValue());
        }
        this.mState = loginState;
        updateRunTimeInfo();
        nativeUpdateState(loginState.intValue());
    }

    public void onUpdateNetPolicy() {
        Log.info(TAG, "onUpdateNetPolicy");
        if (!checkServiceRunning()) {
            Log.info(TAG, "service is not running");
            return;
        }
        if (this.mLastMode != LaunchMode.LAUNCH_TYPE_LAST) {
            onRestartTun();
        }
        List<ResType> l3vpnResources = IPRcManager.getInstance().getL3vpnResources();
        if (l3vpnResources != null) {
            nativeUpdateRclist(l3vpnResources);
        }
    }

    public void onRestartTun() {
        if (!checkServiceRunning()) {
            Log.info(TAG, "service is not running");
            return;
        }
        Log.info(TAG, "restart tun!!");
        nativeRestartTun();
    }

    private void updateRunTimeInfo() {
        Log.info(TAG, "update runtime info");
        nativeUpdateRuntimeInfo(getRuntimeInfo());
    }

    @Override // com.sangfor.ssl.l3vpn.service.EasyappSvpnService.ICallback
    public void onServiceStart(EasyappSvpnService.IManager iManager, LaunchMode launchMode, LoginState loginState) {
        this.mTunManager = iManager;
        if (checkServiceRunning()) {
            if (this.mMode != launchMode) {
                Log.error(TAG, "invalid mode!!");
                return;
            } else {
                updateLoginState(loginState);
                return;
            }
        }
        String str = TAG;
        Log.info(str, "start service mode is " + launchMode.name() + "; state is " + loginState.name() + ";");
        this.mLastMode = this.mMode;
        this.mMode = launchMode;
        this.mState = loginState;
        onUpdateNetPolicy();
        if (!nativeStartProxy(this.mMode.intValue(), this.mState.intValue(), getRuntimeInfo(), this.mAppContext.getFilesDir().getAbsolutePath())) {
            dispatchVpnStatusChangedEvent(VpnStatus.VPN_STATUS_DISCONNECTED.intValue(), 31);
        }
        String str2 = TAG;
        Log.info(str2, "nativeStartProxy end." + Log.getTimestamp());
    }

    @Override // com.sangfor.ssl.l3vpn.service.EasyappSvpnService.ICallback
    public void onServiceRevoke(EasyappSvpnService.IManager iManager) {
        IVpnStatusChangedListener iVpnStatusChangedListener;
        Log.info(TAG, "Tunnel service revoke");
        EasyappSvpnService.IManager iManager2 = this.mTunManager;
        if (iManager2 != null) {
            iManager2.closeTunnel();
        }
        stopService();
        synchronized (this.mList) {
            Iterator<WeakReference<IVpnStatusChangedListener>> it = this.mList.iterator();
            while (it.hasNext()) {
                WeakReference<IVpnStatusChangedListener> next = it.next();
                if (next != null && (iVpnStatusChangedListener = next.get()) != null) {
                    iVpnStatusChangedListener.onPermissionRevoke();
                }
            }
        }
    }

    @Override // com.sangfor.ssl.l3vpn.service.EasyappSvpnService.ICallback
    public void onServiceStop() {
        this.mVpnStatus = VpnStatus.VPN_STATUS_NONE;
        this.mTunManager = null;
        this.mMode = LaunchMode.LAUNCH_TYPE_LAST;
    }

    public LaunchMode getLaunchMode() {
        return this.mMode;
    }

    public void registerListener(IVpnStatusChangedListener iVpnStatusChangedListener) {
        if (iVpnStatusChangedListener == null) {
            throw new IllegalArgumentException("registerListener is null, invalid arugment.");
        }
        unregisterListener(iVpnStatusChangedListener);
        synchronized (this.mList) {
            this.mList.add(new WeakReference<>(iVpnStatusChangedListener));
        }
    }

    public void unregisterListener(IVpnStatusChangedListener iVpnStatusChangedListener) {
        if (iVpnStatusChangedListener == null) {
            throw new IllegalArgumentException("unregisterListener is null, invalid arugment.");
        }
        synchronized (this.mList) {
            Iterator<WeakReference<IVpnStatusChangedListener>> it = this.mList.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                } else if (it.next().get() == iVpnStatusChangedListener) {
                    it.remove();
                    break;
                }
            }
        }
    }

    public void stopService() {
        closeTunnel();
        Log.info(TAG, "stop vpn service!");
        nativeStopProxy();
        this.mTunManager.stopVpnService();
        this.mTunManager = null;
        this.mMode = LaunchMode.LAUNCH_TYPE_LAST;
    }

    public void closeTunnel() {
        if (!checkServiceRunning()) {
            Log.info(TAG, "service is not running,cannot stop");
            return;
        }
        Log.info(TAG, "close tunnel!");
        this.mTunManager.closeTunnel();
        this.mVpnStatus = VpnStatus.VPN_STATUS_NONE;
    }

    public synchronized void shutDownTunnel() {
        if (!checkServiceRunning()) {
            Log.warn(TAG, "L3Vpn is already not running!shutDownTunnel returned.");
        } else {
            this.mHandler.post(new Runnable() { // from class: com.sangfor.ssl.l3vpn.service.VpnServiceManager.1
                @Override // java.lang.Runnable
                public void run() {
                    Log.info(VpnServiceManager.TAG, "ShutdownTunnel,stop KeepLiveService,SangforAuthManager vpnLogout");
                    if (VpnServiceManager.getInstance().checkServiceRunning()) {
                        SangforAuthManager.getInstance().vpnLogout();
                    }
                }
            });
        }
    }

    public String getSession() {
        return SystemConfiguration.getInstance().getSessionId();
    }

    public void protect(int i) {
        EasyappSvpnService.IManager iManager = this.mTunManager;
        if (iManager == null) {
            String str = TAG;
            Log.error(str, "protect fd failed, mTunManager is NULL! fd = " + i);
        } else if (iManager.protect(i)) {
        } else {
            String str2 = TAG;
            Log.error(str2, "protect fd failed! fd = " + i);
        }
    }

    public int openTunnel(String str) {
        TunConfig createVpnConfig;
        int i = -1;
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        String str2 = TAG;
        Log.info(str2, "open tunnel, host =  " + str);
        try {
            if (isIsolationEnable()) {
                createVpnConfig = this.mConfigUtil.createIsolationConfig(str);
            } else {
                createVpnConfig = this.mConfigUtil.createVpnConfig(str);
            }
            i = this.mTunManager.openTunnel(createVpnConfig).getFd();
        } catch (Exception e) {
            Log.error(TAG, "open Tunnel Fail, ", e);
        }
        if (i >= 0) {
            Log.info(TAG, "opt_l3vpn_open_tunnel_success");
        } else {
            Log.info(TAG, "opt_l3vpn_open_tunnel_failed");
        }
        String str3 = TAG;
        Log.info(str3, "open tunnel finish, fd = " + i);
        return i;
    }

    public void dispatchPacketEvent(int i, PacketInfo packetInfo) {
        String str = TAG;
        Log.info(str, "PacketInfo : source: " + packetInfo.srcHost + ":" + packetInfo.srcPort + ";dest :" + packetInfo.host + ":" + packetInfo.port + ";uid is " + packetInfo.uid);
        if (i == PacketEvent.PACKET_EVENT_NONE.intValue()) {
            Log.info(TAG, "eType is invalid arugment.");
        } else if (i == PacketEvent.PACKET_EVENT_GET_APPINFO.intValue()) {
            showAndSaveNetinfo(packetInfo);
        } else {
            Log.info(TAG, "not supported.");
        }
    }

    private void showAndSaveNetinfo(PacketInfo packetInfo) {
        NetworkInterceptInfoModel networkInterceptInfoModel = NetworkInterceptInfoModel.getInstance();
        if (networkInterceptInfoModel != null) {
            networkInterceptInfoModel.onPacketInfoCallback(packetInfo);
        }
    }

    public void dispatchVpnStatusChangedEvent(int i, int i2) {
        IVpnStatusChangedListener iVpnStatusChangedListener;
        String str = TAG;
        Log.info(str, "current states is " + i);
        VpnStatus ValueOf = VpnStatus.ValueOf(i);
        this.mVpnStatus = ValueOf;
        int i3 = AnonymousClass2.$SwitchMap$com$sangfor$ssl$l3vpn$service$VpnStatus[ValueOf.ordinal()];
        if (i3 == 1) {
            Log.info(TAG, "opt_l3vpn_init");
        } else if (i3 == 2) {
            Log.info(TAG, "opt_l3vpn_event_tunnel_connect");
        } else if (i3 == 3) {
            Log.info(TAG, "opt_l3vpn_event_tunnel_reconnecting");
        } else if (i3 == 4) {
            handleDisconnectedErrcode(i2);
        }
        synchronized (this.mList) {
            Iterator<WeakReference<IVpnStatusChangedListener>> it = this.mList.iterator();
            while (it.hasNext()) {
                WeakReference<IVpnStatusChangedListener> next = it.next();
                if (next != null && (iVpnStatusChangedListener = next.get()) != null) {
                    iVpnStatusChangedListener.onVpnStatusChanged(ValueOf, i2);
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.sangfor.ssl.l3vpn.service.VpnServiceManager$2  reason: invalid class name */
    /* loaded from: classes2.dex */
    public static /* synthetic */ class AnonymousClass2 {
        static final /* synthetic */ int[] $SwitchMap$com$sangfor$ssl$l3vpn$service$VpnStatus;

        static {
            int[] iArr = new int[VpnStatus.values().length];
            $SwitchMap$com$sangfor$ssl$l3vpn$service$VpnStatus = iArr;
            try {
                iArr[VpnStatus.VPN_STATUS_INIT.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$sangfor$ssl$l3vpn$service$VpnStatus[VpnStatus.VPN_STATUS_CONNECTED.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$com$sangfor$ssl$l3vpn$service$VpnStatus[VpnStatus.VPN_STATUS_RECONNECTING.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$com$sangfor$ssl$l3vpn$service$VpnStatus[VpnStatus.VPN_STATUS_DISCONNECTED.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
        }
    }

    private void handleDisconnectedErrcode(int i) {
        if (i == 8) {
            Log.info(TAG, "opt_l3vpn_event_timeout");
        } else if (i == 12) {
            Log.info(TAG, "opt_l3vpn_tunnel_stop");
        } else {
            String str = TAG;
            Log.info(str, "opt_l3vpn_event_error " + i);
        }
    }

    public boolean checkServiceRunning() {
        return (this.mMode == LaunchMode.LAUNCH_TYPE_LAST || this.mTunManager == null) ? false : true;
    }

    private VpnServiceManager() {
        this.mHandler = new Handler(Looper.getMainLooper());
        this.mAppContext = null;
        this.mIsInit = new AtomicBoolean(false);
        this.mList = new ArrayList<>();
        this.mVpnStatus = VpnStatus.VPN_STATUS_NONE;
        this.mCapturePtr = 0L;
        this.mCaptureLock = new Object();
        this.mTunManager = null;
        this.mVpnStatus = VpnStatus.VPN_STATUS_NONE;
        this.mMode = LaunchMode.LAUNCH_TYPE_LAST;
        this.mLastMode = LaunchMode.LAUNCH_TYPE_LAST;
        this.mConfigUtil = new VpnConfigUtil();
    }

    public VpnStatus getmVpnStatus() {
        return this.mVpnStatus;
    }

    public Intent prepare(Context context) {
        return EasyappSvpnService.prepare(context);
    }

    /* loaded from: classes2.dex */
    private class VpnConfigUtil {
        private IPRcManager mManager;

        private VpnConfigUtil() {
            this.mManager = IPRcManager.getInstance();
        }

        public TunConfig createVpnConfig(String str) {
            List<Pair<String, String>> vpnRoutes;
            String vpnHost = SystemConfiguration.getInstance().getVpnHost();
            if (TextUtils.isEmpty(vpnHost)) {
                Log.error(VpnServiceManager.TAG, "getVpnHost is empty.");
                return null;
            }
            ArrayList arrayList = new ArrayList();
            arrayList.add(str);
            arrayList.add(vpnHost);
            if (VpnServiceManager.this.isVpnLineEnable()) {
                vpnRoutes = this.mManager.getLineRoutes(arrayList);
            } else {
                vpnRoutes = this.mManager.getVpnRoutes(arrayList);
            }
            List<Pair<String, String>> list = vpnRoutes;
            List<String> dnsserver = getDnsserver();
            if (dnsserver == null) {
                dnsserver = getDefaultServer();
            }
            List<String> list2 = dnsserver;
            addDnsServerFromJavaIfNeed(VpnServiceManager.this.mAppContext, list2);
            return createConfig(str, list, list2, AppStore.getInstance().getWhiteAppList(), null);
        }

        private void addDnsServerFromJavaIfNeed(Context context, List<String> list) {
            if (list == null) {
                list = new ArrayList<>();
            }
            if (RomUtils.checkIsHuaweiRom()) {
                Log.info(VpnServiceManager.TAG, "check is  huawei rom. add fix host.");
                if (!list.contains("10.8.2.1")) {
                    list.add("10.8.2.1");
                }
                if (!list.contains("10.8.2.2")) {
                    list.add("10.8.2.2");
                }
                if (!list.contains("8.8.8.8")) {
                    list.add("8.8.8.8");
                }
                if (!list.contains("208.67.222.222")) {
                    list.add("208.67.222.222");
                }
                if (!list.contains("180.76.76.76")) {
                    list.add("180.76.76.76");
                }
                if (list.contains("223.5.5.5")) {
                    list.add("223.5.5.5");
                    return;
                }
                return;
            }
            Log.info(VpnServiceManager.TAG, "not huawei rom. skip fix host.");
        }

        public TunConfig createIsolationConfig(String str) {
            ArrayList arrayList = new ArrayList();
            String vpnHost = SystemConfiguration.getInstance().getVpnHost();
            if (TextUtils.isEmpty(vpnHost)) {
                Log.error(VpnServiceManager.TAG, "getVpnHost is empty.");
                return null;
            }
            arrayList.add(str);
            arrayList.add(vpnHost);
            List<Pair<String, String>> lineRoutes = this.mManager.getLineRoutes(arrayList);
            List<String> dnsserver = getDnsserver();
            if (dnsserver == null) {
                dnsserver = getDefaultServer();
            }
            List<String> list = dnsserver;
            addDnsServerFromJavaIfNeed(VpnServiceManager.this.mAppContext, list);
            List<String> whiteAppList = AppStore.getInstance().getWhiteAppList();
            if (whiteAppList == null) {
                whiteAppList = new ArrayList<>();
                whiteAppList.add("");
            } else if (whiteAppList.size() == 0) {
                whiteAppList.add("");
            }
            return createConfig(str, lineRoutes, list, whiteAppList, null);
        }

        private TunConfig createConfig(String str, List<Pair<String, String>> list, List<String> list2, List<String> list3, List<String> list4) {
            TunConfig tunConfig = new TunConfig();
            tunConfig.virIp = str;
            tunConfig.routes = list;
            tunConfig.dnsServer = list2;
            tunConfig.mtu = 1400;
            tunConfig.description = "SANGFOR SSL VPN";
            tunConfig.launchMode = LaunchMode.NET_TYPE_VPN;
            tunConfig.whiteList = list3;
            tunConfig.blackList = list4;
            return tunConfig;
        }

        private List<String> getDnsserver() {
            String[] split;
            Map<String, String> dnsInfo = ResourceManager.getInstance().getDnsInfo();
            ArrayList arrayList = new ArrayList();
            if (dnsInfo == null) {
                return null;
            }
            String str = dnsInfo.get("dnsserver");
            if (TextUtils.isEmpty(str) || (split = str.split(";")) == null || split.length == 0) {
                return null;
            }
            for (String str2 : split) {
                arrayList.add(str2);
            }
            return arrayList;
        }

        private List<String> getDefaultServer() {
            ArrayList arrayList = new ArrayList();
            arrayList.add("114.114.114.114");
            arrayList.add("8.8.8.8");
            return arrayList;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean isVpnLineEnable() {
        return SystemConfiguration.getInstance().isVpnLineEnable();
    }

    private boolean isIsolationEnable() {
        return SystemConfiguration.getInstance().isIsolationEnable();
    }

    private String getRuntimeInfo() {
        SystemConfiguration systemConfiguration = SystemConfiguration.getInstance();
        SystemConfiguration.VpnInfo vpnInfo = systemConfiguration.getVpnInfo();
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("Domain:");
        stringBuffer.append(systemConfiguration.getVpnDomain());
        stringBuffer.append("\r\n");
        if (vpnInfo != null) {
            stringBuffer.append("Host:");
            stringBuffer.append(vpnInfo.getHost());
            stringBuffer.append("\r\n");
            stringBuffer.append("Port:" + vpnInfo.getPort() + "\r\n");
        } else {
            Log.error(TAG, "getRuntimeInfo vpnInfo is null!");
        }
        Map<String, String> dnsInfo = ResourceManager.getInstance().getDnsInfo();
        if (dnsInfo != null) {
            String str = dnsInfo.get("filter");
            if (str != null) {
                stringBuffer.append("filter:");
                stringBuffer.append(str);
                stringBuffer.append("\r\n");
            }
            String str2 = dnsInfo.get("data");
            if (str2 != null) {
                str2 = str2.replace(':', '#');
                stringBuffer.append("data:" + str2);
            }
            List<Map<String, Object>> ip2Dns = NetworkWhiteListParser.getInstance().getIp2Dns();
            for (int i = 0; i < ip2Dns.size(); i++) {
                Map<String, Object> map = ip2Dns.get(i);
                for (String str3 : map.keySet()) {
                    List list = (List) map.get(str3);
                    for (int i2 = 0; i2 < list.size(); i2++) {
                        String str4 = (String) list.get(i2);
                        if (str2 == null) {
                            stringBuffer.append("-1_" + str3 + "_" + str4);
                        } else {
                            stringBuffer.append(";-1_" + str3 + "_" + str4);
                        }
                    }
                }
            }
            stringBuffer.append("\r\n");
            String str5 = dnsInfo.get("dnsserver");
            if (str5 != null) {
                stringBuffer.append("dnsserver:");
                stringBuffer.append(str5);
                stringBuffer.append("\r\n");
            }
        }
        String linkCipher = systemConfiguration.getLinkCipher("L3VPN");
        if (linkCipher != null) {
            stringBuffer.append("L3VPN:");
            stringBuffer.append(linkCipher);
            stringBuffer.append("\r\n");
        }
        String enginValue = systemConfiguration.getEnginValue("L3VPN");
        if (enginValue != null) {
            stringBuffer.append("L3VPNENG:");
            stringBuffer.append(enginValue);
            stringBuffer.append("\r\n");
        }
        String gMVersion = systemConfiguration.getGMVersion();
        if (gMVersion != null) {
            stringBuffer.append("GMVERSION:");
            stringBuffer.append(gMVersion);
            stringBuffer.append("\r\n");
        }
        stringBuffer.append("SSL:");
        stringBuffer.append(systemConfiguration.sslProtocolSupported() ? "1" : "0");
        stringBuffer.append("\r\n");
        stringBuffer.append("EMMLine:");
        stringBuffer.append(isEMMLineEnable() ? "1" : "0");
        stringBuffer.append("\r\n");
        stringBuffer.append("Candidate:");
        stringBuffer.append(LineSelectionModel.getInstance().getCandidates());
        Log.info(TAG, stringBuffer.toString());
        return stringBuffer.toString();
    }

    public String getDnsServerFromJava() {
        String str = "";
        for (InetAddress inetAddress : new AndroidDnsServer().getDnsServer(this.mAppContext)) {
            String hostAddress = inetAddress.getHostAddress();
            if (!TextUtils.isEmpty(hostAddress) && !hostAddress.startsWith("0.")) {
                str = str + ";" + hostAddress;
            }
        }
        String replaceFirst = str.replaceFirst(";", "");
        Log.info(TAG, "getDnsServerFromJava getDnsServer=" + replaceFirst);
        return replaceFirst;
    }

    public boolean startCapturePacket(String str, int i, long j, long j2, boolean z) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        int i2 = i <= 0 ? 262144 : i;
        long j3 = j <= 0 ? Long.MAX_VALUE : j;
        long j4 = j2 <= 0 ? Long.MAX_VALUE : j2;
        synchronized (this.mCaptureLock) {
            if (this.mCapturePtr != 0) {
                return false;
            }
            long nativeStartCapturePacket = nativeStartCapturePacket(str, i2, j3, j4, z);
            this.mCapturePtr = nativeStartCapturePacket;
            return nativeStartCapturePacket != 0;
        }
    }

    public boolean isCapturing() {
        boolean z;
        synchronized (this.mCaptureLock) {
            z = this.mCapturePtr != 0;
        }
        return z;
    }

    public boolean isCaptureComplete() {
        synchronized (this.mCaptureLock) {
            long j = this.mCapturePtr;
            if (j == 0) {
                return true;
            }
            return nativeIsCaptureComplete(j);
        }
    }

    public void stopCapturePacket() {
        synchronized (this.mCaptureLock) {
            long j = this.mCapturePtr;
            if (j == 0) {
                return;
            }
            nativeStopCapturePacket(j);
            this.mCapturePtr = 0L;
        }
    }
}
